/*
 * AttributeTest.java
 *
 * Created on February 4, 2007, 8:44 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.smallx.xpath.streaming;

import com.smallx.xpath.DynamicContext;
import org.infoset.xml.Attribute;
import org.infoset.xml.Element;
import org.infoset.xml.Item;
import org.infoset.xml.Name;

/**
 *
 * @author alex
 */
public class AttributeTest implements Predicate {
   
   Name name;
   String value;
   /** Creates a new instance of AttributeTest */
   public AttributeTest(Name name) {
      this(name,null);
   }
   public AttributeTest(Name name,String value) {
      this.name = name;
      this.value = value;
   }
   
   public boolean test(Item item, DynamicContext context) {
      if (item instanceof Element) {
         Element e = (Element)item;
         Attribute att = e.getAttributes().get(name);
         if (att!=null) {
            return value==null ? true : value.equals(att.getText());
         }
      }
      return false;
   }
   
}
